Num = input()
Num2 = None

def Check(Num4):
    if Num4 % 2 == 0:
        return Num4 == 2
    Checker = 3
    while Checker * Checker <= Num4 and Num4 % Checker != 0:
        Checker += 2
    return Checker * Checker > Num4

if len(Num) == 4:
    for i in range(4):
        Cifra = Num[i]
        Num3 = None
        Num5 = ""
        for NextC in range(i, 4):
            Num5 = Num5 + Num[NextC]
            if Check(int(Num5)) == True:
                Num3 = Num5
        if Num3 != None:
            if Num2 == None or Num2 != None and Num2 < int(Num3):
                Num2 = int(Num3)

if Num2 != None:
    print(Num2)
else:
    print(0)